package top.as.sean.dao.plugin;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Component;
import top.as.sean.dao.entity.pojo.system.DataDict;
import top.as.sean.dao.mapper.system.DataDictMapper;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 字典翻译逻辑
 *
 * @author: ArchieSean
 * @create: 2022/12/31
 */
@Component
public class DictPlugin {
    /**
     * 数据字典数据层
     */
  @Resource
    private DataDictMapper dataDictMapper;

    /**
     * 查询数据字典值
     *
     * @param code 字典编码
     * @return map
     */
    public Map<String, String> getDataDict(@NotNull String code) {
        return dataDictMapper.selectList(Wrappers.lambdaQuery(DataDict.class).eq(DataDict::getParentCode, code))
                .stream().collect(Collectors.toMap(DataDict::getCode, DataDict::getDictName));

    }
}
